package club.twelveblog.tblog.dao;

import club.twelveblog.tblog.common.vo.BlogInfoVo;
import club.twelveblog.tblog.entity.BlogInfo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;


@Repository
public interface ResultRepository extends JpaRepository<BlogInfo, Long>,JpaSpecificationExecutor<BlogInfoVo>{

//    @Query(value = "SELECT new " +
//            "club.twelveblog.tblog.common.vo.BlogInfoVo" +
//            "(b.blog_id,b.blog_title,b.blog_preface,b.blog_views,b.createTime,u.user_id,u.user_nick_name,u.authorImg) " +
//            "FROM BlogInfo b LEFT JOIN ")
//    List<BlogInfoVo> findBlogByPojo(String category);
    //b.blog_id,b.blog_title,b.blog_preface,b.blog_views,b.u_id,b.blog_content,u.user_nick_name,u.author_img
//    @Query(value = "SELECT b.blog_id as bid," +
//            "b.blog_title as bTitle," +
//            "b.blog_preface as bPreface," +
//            "b.blog_views as bViews," +
//            "b.create_time as create_Time," +
//            "b.u_id as uid," +
//            "u.user_nick_name as nickName," +
//            "u.author_img as userImg " +
//            "FROM tb_bloginfo b " +
//            "left join tb_category c on b.c_id=c.category_id," +
//            "left join tb_user u on b.u_id=u.user_id " +
//            "WHERE c.category_name=:category",nativeQuery = true)
//        List<BlogInfoVo> findBlogByPojo(String category);
//    @Query(value = "SELECT b.blog_id as bid,b.blog_title as bTitle,b.blog_preface as bPreface,b.blog_views as bViews,b.create_time as create_Time,b.u_id as uid,u.user_nick_name as nickName,u.author_img as userImg FROM tb_bloginfo b,tb_category c,tb_user u WHERE b.c_id=c.category_id AND b.u_id=u.user_id  AND c.category_name=:category",nativeQuery = true)
//    List<Object[]> findBlogByCategory(@Param("category") String category);

    @Query(value = "SELECT b.blog_id as bid,b.blog_title as bTitle,b.blog_preface as bPreface,b.blog_views as bViews,b.create_time as create_Time,b.u_id as uid,u.user_nick_name as nickName,u.author_img as userImg FROM tb_bloginfo b,tb_category c,tb_user u WHERE b.c_id=c.category_id AND b.u_id=u.user_id  AND c.category_name=:category",nativeQuery = true)
    List<Object[]> QueryBlogVo(@Param("category") String category);

}
